const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        msgs1:[],
        sc:0,
        id:0,
        files2: [],
        files3: [],
        filestr2: '',
        url: App.Config.basePath,
        buttons3: [{
            type: 'submit',
            url: App.renderUrl('empty', 'index'),
            title: ``
        }]
    },

   //弹出提示信息
    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function() {},

    //页面加载
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option,
                id:option.id
            })
        }
    },

   //页面显示
    onShow() {
        this.getForm1();
        this.getMsgs1();
    },

    //设置输入验证
    getForm1() {
        this.WxValidate = App.WxValidate({
            memo: {
		required:{
			message:'评语：不能为空哟'
		}
	},

        })
    },

    formSubmit1: function (e) {
        if (!this.WxValidate.checkForm(e)) {
            const error = this.WxValidate.errorList[0]
            var msg = `${error.msg}`;
            this.showModal(msg);
            return false
        }else{

            if(this.data.sc==0)
            {
                this.showModal('请选择评分');
                return;
            }
            else
            {
                var data = e.detail.value;
                data =App.Tools.extend(data,{
                    f:1,
                    id:this.data.id,
                    rid: this.data.globalOption.rid,
                    mid: wx.getStorageSync("mid"),
                    photo: this.data.files2,
                    sc:this.data.sc
                });
                App.HttpService.saveData(data,"/assesss_Add").then(data => {
                    App.WxService.showToast({
                        title: "评价成功!",
                        icon: 'success',
                        duration: 1500,
                    });
                    setTimeout(function () {
                        wx.navigateBack();
                    }, 1500)
                });
            }


        }
    },
    formReset1: function() {
        console.log('form发生了reset事件')
    },
    select(e){
        this.setData({
            sc:e.currentTarget.dataset.id
        })
    },

    getMsgs1(isShow){
        //调用数据
        let param = {
            f:1,
            id:this.data.id,
            loadmsg:`正在加载中`
        };


        App.HttpService.getData(param,"/assesss_List").then(data=>{
            this.setData({
                msgs1: data
            });
        });
    },

    changepic: function (values) {
        if (values.detail) {
            values = values.detail.value;
        } else if (App.Tools.isString(values)) {
            values = values.split(",");
        }
        var files = [];
        for (var i = 0; i < values.length; i++) {
            files[i] = App.renderImage(values[i])
        }
        this.setData({
            files3: files,
            filestr3: (files || []).join(',').replace(/^[]/, '')
        });
    },
    chooseImage2: function (e) {
        var that = this;
        var cc = App.globalData.cid;
        wx.chooseImage({
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths;
                for (var i = 0; i < tempFilePaths.length; i++) {
                    wx.uploadFile({
                        url: App.getActionUrl('/uploadFile'), //仅为示例，非真实的接口地址
                        filePath: tempFilePaths[0],
                        name: 'file',
                        success: function (res) {

                            console.log(res.data);
                            var data = App.Tools.fromJson(res.data);
                            console.log(data);
                            var files = that.data.files2.concat(data[0].addr);
                            var files33 = that.data.files3.concat(that.data.url + data[0].addr);
                            that.setData({
                                files2: files,
                                files3: files33,
                                filestr2: (files || []).join(',').replace(/^[]/, '')
                            });

                            App.globalData.cid = cc;
                        }
                    })
                }
            }
        })


    },
    previewImage2: function (e) {
        wx.previewImage({
            current: e.currentTarget.id, // 当前显示图片的http链接
            urls: this.data.files3 // 需要预览的图片http链接列表
        })
    },


})
